<script>
	/**
	 * vuex管理登陆状态，具体可以参考官方登陆模板示例
	 */
	
	import {
		mapMutations
	} from 'vuex';
	
	export default {
		
		
		globalData: {  
			//图片地址
            // imageAddress: 'http://172.23.38.205:8082',
			imageAddress: 'http://img.nczywc.cn',//上线地址
			// 请求API的URL
			// http:'http://localhost:8086',
			// http:'http://192.168.0.108:8087',
			// http:'http://192.168.0.108:8086',//app本地
			// http:'https://api.nczywc.cn',//小程序上线地址
			http:'http://yphapi.nczywc.cn',//H5线上地址
			// http:'http://119.3.56.202:9080',//新服务器地址
			// STOREID:'DP4896226',//亿品分公司id
			// STOREID:'',
			// http:'https://mnapi.nczywc.cn',//线上测试地址
			
        },
		
		
		// 赋值 
		// getApp().globalData.text = 'test'
		//取值
		// console.log(getApp().globalData.imageAddress); 
		data() {
			return {
				BRAND: '',
				MODEL: '',
				OS: '',
				OSVERSION: '',
				SCREEN: '',
				RESOLUTION: '',
				MIDU: '',
				UQID: '',
				OSID: '', 
				TVERSION: '',
				TYPE: '',//A.Android B.iPhone C.iPad
				SIGNATURE: '',
			};
		},
		onLaunch: function() {
			// #ifdef MP
			this.updateM();
			// #endif
			this.getSystemInfo();
			this.saveSystemInfo();
			
			let userInfo = uni.getStorageSync('userInfo') || '';
			//如果userInfo得到空值，那么未登录
			if(userInfo){
				this.login(userInfo);
			}
			
		},
		...mapMutations(['login']),
		onShow: function() { 
			//#ifdef APP-PLUS
			 console.log("*/**********************plus.runtime.launcherLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL: "+plus.runtime.arguments);
			var args= plus.runtime.arguments;  
			if(args.substr(0,3) == 'yph'){
				// if(args.substr(0,8) == 'hbuilder'){  
				// 处理args参数，如直达到某新页面等  
				var roomids = args.split("&")[1];
				
				console.log("plus.runtime.launcherLLLLLLLLLLLLLLLLLLLLLLL: "+roomids);
				uni.hideLoading();
				   uni.navigateTo({
					   url:'/pagesun/live/live?role=21&roomid='+roomids
				   })
			} 
			
			//#endif
			this.flesh();
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		
		
	
		
		methods: {
			//升级版本
			updateM(){
				const updateManager = uni.getUpdateManager();
				updateManager.onCheckForUpdate(function(res) {
					// 请求完新版本信息的回调
					if (res.hasUpdate) {
						updateManager.onUpdateReady(function(res2) {
							uni.showModal({
								title: '更新提示',
								content: '发现新版本，是否重启应用?',
								cancelColor:'#eeeeee',
								confirmColor:'#FF0000',
								success(res2) {
									if (res2.confirm) {
										// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
										updateManager.applyUpdate();
									}
								}
							});
						});
					}
				});
	
	
				updateManager.onUpdateFailed(function(res) {
					// 新的版本下载失败
					uni.showModal({
						title: '提示',
						content: '检查到有新版本，但下载失败，请检查网络设置',
						success(res) {
							if (res.confirm) {
								// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
								updateManager.applyUpdate();
							}
						}
					});
				});
			},
			
			
			async flesh(){
				//#ifdef H5
				this.$http.post("/user/flesh",{
					SIGNATURE : uni.getStorageSync("SIGNATURE"),
					TOKEN: uni.getStorageSync("userInfo").TOKEN,
				}).then((res) => {
					
					
				}).catch((err)=>{
					console.log('request fail', err);
				})
				//#endif
				//#ifndef H5
				uni.request({
					url: this.$options.globalData.http+'/user/flesh', //仅为示例，并非真实接口地址。
					data: {
						SIGNATURE : uni.getStorageSync("SIGNATURE"),
						TOKEN: uni.getStorageSync("userInfo").TOKEN,
					},
					header: {
						'content-type':'application/x-www-form-urlencoded',
					},
					success: (res) => {
						
					}
				});
				//#endif
				
			},
			
			/**
			 * 获取手机注册信息
			 */
			getSystemInfo: function () {
				uni.getSystemInfo({
					success: (res) => {
						this.BRAND = res.model.split(" ")[0];
						this.MODEL = res.model;
						this.OS = res.platform;
						this.OSVERSION = res.system;
						this.SCREEN = res.windowHeight +"*"+res.windowWidth;
						this.RESOLUTION = res.screenHeight +"*"+res.screenWidth;
						this.TVERSION = res.version;
						if (res.platform == 'ios'){
							this.TYPE = 'B';
						}else if (res.platform == 'android'){
							this.TYPE = 'A';
						}else {
							this.TYPE = 'C';
						};
						this.MIDU = res.pixelRatio;
						// #ifdef APP-PLUS  
						var uqid = plus.device.imei;
						if(this.TYPE == 'A'){
							var mainActivity = plus.android.runtimeMainActivity();
							var Settings= plus.android.importClass("android.provider.Settings");
							this.OSID = Settings.Secure.getString(mainActivity.getContentResolver(),Settings.Secure.ANDROID_ID);
						}
						var uqids = uqid.split(",");
						this.UQID = uqids[0];
						// #endif  
						
					}
				})
			},
			
			/**
			 *  发送请求保存手机注册信息
			 */
			saveSystemInfo:function () {
				console.log("进入保存注册号的方法")
				
				// #ifdef APP-PLUS
				// uni.setStorageSync("SIGNATURE",(new Date().getTime().toString()+new Date().getTime().toString()+new Date().getTime().toString()).substring(0,36));
				uni.request({
					url: this.$options.globalData.http+'/common/regist', //仅为示例，并非真实接口地址。
					data: {
						BRAND : this.BRAND,
						MODEL : this.MODEL,
						OS : this.OS,
						OSVERSION: this.OSVERSION,
						SCREEN: this.SCREEN,
						RESOLUTION: this.RESOLUTION,
						MIDU: this.MIDU,
						UQID: this.UQID,
						OSID: this.OSID,
						TVERSION: this.TVERSION,
						TYPE: this.TYPE,//A.Android B.iPhone C.iPad
					},
					header: {
						'content-type':'application/x-www-form-urlencoded',
					},
					success: (res) => {
						//保存信息  存储在本地缓存中指定的 key 中
						uni.setStorageSync("SIGNATURE",res.data.OBJECT.SIGNATURE);
					}
				});
				//#endif
				// #ifdef MP
				console.log("进入保存注册号的方法-微信")
				// uni.setStorageSync("SIGNATURE",(new Date().getTime().toString()+new Date().getTime().toString()+new Date().getTime().toString()).substring(0,36));
				uni.request({
					url: this.$options.globalData.http+'/common/regist', //仅为示例，并非真实接口地址。
					data: {
						BRAND : this.BRAND,
						MODEL : this.MODEL,
						OS : this.OS,
						OSVERSION: this.OSVERSION,
						SCREEN: this.SCREEN,
						RESOLUTION: this.RESOLUTION,
						MIDU: this.MIDU,
						UQID: this.UQID,
						OSID: this.OSID,
						TVERSION: this.TVERSION,
						TYPE: this.TYPE,//A.Android B.iPhone C.iPad
					},
					method:"POST",
					header: {
						'content-type':'application/x-www-form-urlencoded',
					},
					success: (res) => {
						console.log("获取的终端信息",res.data.OBJECT);
						uni.setStorageSync("SIGNATURE",res.data.OBJECT.SIGNATURE);
						console.log("缓存的终端号",uni.getStorageSync("SIGNATURE"));
					}
				});
				uni.login({
					// 1.wx获取登录用户code
					provider: 'weixin',
					success: function(loginRes) {
						let code = loginRes.code;
						//2.将用户登录code传递到后台置换用户SessionKey、OpenId等信息
						uni.request({
							url: getApp().globalData.http+'/user/wxOpenId', //仅为示例，并非真实接口地址。
							data: {
								CODE: code,
							},
							method:"POST",
							header: {
								'content-type':'application/x-www-form-urlencoded',
							},
							success: (res) => {
								console.log("微信登录返信息",res)
								//保存信息  存储在本地缓存中指定的 key 中
								uni.setStorageSync("OPENID",res.data.OBJECT.OPENID);
								if(!uni.getStorageSync("SIGNATURE")){
									uni.setStorageSync("SIGNATURE",res.data.OBJECT.OPENID+"12345678");
								}
								console.log("缓存中的OPENID",uni.getStorageSync("OPENID"));
								console.log("二次缓存中的终端号",uni.getStorageSync("SIGNATURE"));
							}
						});
					},
				});
				
				//#endif
				//#ifdef H5
				 this.$http.post('/common/regist',{
					 BRAND : this.BRAND,
					 MODEL : this.MODEL,
					 OS : this.OS,
					 OSVERSION: this.OSVERSION,
					 SCREEN: this.SCREEN,
					 RESOLUTION: this.RESOLUTION,
					 MIDU: this.MIDU,
					 UQID: this.UQID,
					 OSID: this.OSID,
					 TVERSION: this.TVERSION,
					 TYPE: this.TYPE,//A.Android B.iPhone C.iPad
				 }).then((res)=>{
						//保存信息  存储在本地缓存中指定的 key 中
						uni.setStorageSync("SIGNATURE",res.data.OBJECT.SIGNATURE);
                }).catch((err)=>{
                    console.log('request fail', err);
                })
				//#endif
			},
			
			
			
			...mapMutations(['login'])
		},
		
	}
	
</script>

<style lang='scss'>
	
	/* #ifndef APP-PLUS-NVUE */
	@import url("static/iconfont/iconfont.css");
	/* @import url("static/font/fontAwesome.wxss"); */
	
	/*
		全局公共样式和字体图标
	*/
   
	@font-face {
		font-family: yticon;
		font-weight: normal;
		font-style: normal;
		src: url('https://at.alicdn.com/t/font_1078604_w4kpxh0rafi.ttf') format('truetype');
		
	}
	
	.yticon {
		font-family: "yticon" !important;
		font-size: 16px;
		font-style: normal;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
	}
	.icon-yiguoqi1:before {	//地球
		content: "\e700";
	}

	.icon-iconfontshanchu1:before {	//垃圾箱
		content: "\e619";
	}

	.icon-iconfontweixin:before {	//红包
		content: "\e611";
	}

	.icon-alipay:before {		//支付
		content: "\e636";
	}

	.icon-shang:before {		//上箭头
		content: "\e624";
	}

	.icon-shouye:before {	// 订单
		content: "\e626";
	}

	.icon-shanchu4:before {	//×符号
		content: "\e622";
	}

	.icon-xiaoxi:before {	//消息
		content: "\e618";
	}

	.icon-jiantour-copy:before {//向下箭头
		content: "\e600";
	}

	.icon-fenxiang2:before {	//分享
		content: "\e61e";
	}

	.icon-pingjia:before {	//评价
		content: "\e67b";
	}

	.icon-daifukuan:before {	//代付款
		content: "\e68f";
	}

	.icon-pinglun-copy:before {
		content: "\e612";
	}

	.icon-dianhua-copy:before {	//电话
		content: "\e621";
	}

	.icon-shoucang:before {	//收藏
		content: "\e645";
	}

	.icon-xuanzhong2:before {	//选中
		content: "\e62f";
	}

	.icon-gouwuche_:before {	//购物车
		content: "\e630";
	}

	.icon-icon-test:before {	//定位
		content: "\e60c";
	}

	.icon-icon-test1:before {	//空心星星
		content: "\e632";
	}

	.icon-bianji:before {	//编辑
		content: "\e646";
	}

	.icon-jiazailoading-A:before { //加载
		content: "\e8fc";
	}

	.icon-zuoshang:before {	//左上箭头
		content: "\e613";
	}

	.icon-jia2:before {	//加号
		content: "\e60a";
	}

	.icon-huifu:before {	//
		content: "\e68b";
	}

	.icon-sousuo:before {	//搜索
		content: "\e7ce";
	}

	.icon-arrow-fine-up:before {	//向上箭头
		content: "\e601";
	}

	.icon-hot:before {	//热销
		content: "\e60e";
	}

	.icon-lishijilu:before {	//历史记录
		content: "\e6b9";
	}

	.icon-zhengxinchaxun-zhifubaoceping-:before {	//支付宝标志
		content: "\e616";
	}

	.icon-naozhong:before {	//闹钟
		content: "\e64a";
	}

	.icon-xiatubiao--copy:before {	//小仓库
		content: "\e608";
	}

	.icon-shoucang_xuanzhongzhuangtai:before {	//星星实心
		content: "\e6a9";
	}

	.icon-jia1:before {
		content: "\e61c";
	}

	.icon-bangzhu1:before {	//帮助
		content: "\e63d";
	}

	.icon-arrow-left-bottom:before {  //左下箭头
		content: "\e602";
	}

	.icon-arrow-right-bottom:before {	//右下箭头
		content: "\e603";
	}

	.icon-arrow-left-top:before {	//左上
		content: "\e604";
	}

	.icon-icon--:before {		//消息
		content: "\e744";
	}

	.icon-zuojiantou-up:before { //左箭头
		content: "\e605";
	}

	.icon-xia:before {		//下
		content: "\e62d";
	}

	.icon--jianhao:before {	//减号
		content: "\e60b";
	}

	.icon-weixinzhifu:before {	//微信支付
		content: "\e61a";
	}

	.icon-comment:before {	//评价
		content: "\e64f";
	}

	.icon-weixin:before {	//微信
		content: "\e61f";
	}

	.icon-fenlei1:before {	
		content: "\e620";
	}

	.icon-erjiye-yucunkuan:before {		//钱袋子
		content: "\e623";
	}

	.icon-Group-:before {		//下载
		content: "\e688";
	}

	.icon-you:before {		//左箭头
		content: "\e606";
	}
 
	.icon-forward:before {	//右箭头
		content: "\e607";
	}

	.icon-tuijian:before {	//推荐
		content: "\e610";
	}

	.icon-bangzhu:before {	//？号
		content: "\e679";
	}

	.icon-share:before {	//分享
		content: "\e656";
	}

	.icon-yiguoqi:before {	//已过期
		content: "\e997";
	}

	.icon-shezhi1:before {	//设置
		content: "\e61d";
	}

	.icon-fork:before {	  //X号
		content: "\e61b";
	}

	.icon-kafei:before {	//咖啡
		content: "\e66a";
	}

	.icon-iLinkapp-:before {	//会员
		content: "\e654";
	}

	.icon-saomiao:before {	//扫码
		content: "\e60d";
	}
	
	.icon-shezhi:before {	//设置
		content: "\e60f";
	}

	.icon-shouhoutuikuan:before {	//售后退款
		content: "\e631";
	}

	.icon-gouwuche:before {	//购物车
		content: "\e609";
	}

	.icon-dizhi:before {	//地址
		content: "\e614";
	}

	.icon-fenlei:before {		//分类
		content: "\e706";
	}

	.icon-xingxing:before {		//实心星星
		content: "\e70b";
	}

	.icon-tuandui:before {	//团队
		content: "\e633";
	}

	.icon-zuanshi:before {	//钻石
		content: "\e615";
	}

	.icon-zuo:before {			//左箭头
		content: "\e63c";
	}

	.icon-shoucang2:before {	//实心星星
		content: "\e62e";
	}

	.icon-shouhuodizhi:before {	//待收货
		content: "\e712";
	}

	.icon-yishouhuo:before {	//退款
		content: "\e71a";
	}

	.icon-dianzan-ash:before {	//点赞
		content: "\e617";
	}





	view,
	scroll-view,
	swiper,
	swiper-item,
	cover-view,
	cover-image,
	icon,
	text,
	rich-text,
	progress,
	button,
	checkbox,
	form,
	input,
	label,
	radio,
	slider,
	switch,
	textarea,
	navigator,
	audio,
	camera,
	image,
	video {
		box-sizing: border-box;
	}
	/* 骨架屏替代方案 */
	.Skeleton {
		background: #f3f3f3;
		padding: 20upx 0;
		border-radius: 8upx;
	}

	/* 图片载入替代方案 */
	.image-wrapper {
		font-size: 0;
		background: #f3f3f3;
		border-radius: 4px;

		image {
			width: 100%;
			height: 100%;
			transition: .6s;
			opacity: 0;

			&.loaded {
				opacity: 1;
			}
		}
	}

	.clamp {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		display: block;
	}

	.common-hover {
		background: #f5f5f5;
	}

	/*边框*/
	.b-b:after,
	.b-t:after {
		position: absolute;
		z-index: 3;
		left: 0;
		right: 0;
		height: 0;
		content: '';
		transform: scaleY(.5);
		border-bottom: 1px solid $border-color-base;
	}

	.b-b:after {
		bottom: 0;
	}

	.b-t:after {
		top: 0;
	}

	/* button样式改写 */
	uni-button,
	button {
		height: 80upx;
		line-height: 80upx;
		font-size: $font-lg + 2upx;
		font-weight: normal;

		&.no-border:before,
		&.no-border:after {
			border: 0;
		}
	}

	uni-button[type=default],
	button[type=default] {
		color: $font-color-dark;
	}

	/* input 样式 */
	.input-placeholder {
		color: #999999;
	}

	.placeholder {
		color: #999999;
	}
	/* #endif */
</style>
